package com.zishi.venuesbooking.ac;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.zishi.venuesbooking.BaseActivity;
import com.zishi.venuesbooking.R;

import org.json.JSONException;

import java.io.IOException;

public class LoginActivity extends BaseActivity {

    private  static final String TAG = "LoginActivity";
    private EditText mUsername;
    private EditText mPassword;
    private Button mLogin;
    private Spinner mUserType;


    @Override
    protected int initLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected void initView() {
        mUsername = findViewById(R.id.username);
        mPassword = findViewById(R.id.userpwd);
        mUserType = findViewById(R.id.spinner_user_type);
        mLogin = findViewById(R.id.btn_login);
    }

    @Override
    protected void initData() throws JSONException, IOException {
        mUsername.setText("admin");
        mPassword.setText("admin");
        mUserType.setSelection(0);
        initListener();
    }

    protected void initListener() {
        mLogin.setOnClickListener(v -> {
            String username = mUsername.getText().toString();
            String password = mPassword.getText().toString();
            String userType = mUserType.getSelectedItem().toString();
            if (username.equals("admin") && password.equals("admin") && userType.equals("User")) {
                navigateToWithSlowAnimation(MainActivity.class);
            } else {
                showToast("Invalid username or password");
            }
        });
//        mLogin.setOnClickListener(v -> {
//            navigateTo(Test2Activity.class);
//        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }
}